package com.jjb.www.ui.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.hjq.bar.TitleBar;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.hjq.shape.view.ShapeButton;
import com.hjq.shape.view.ShapeImageView;
import com.jjb.www.R;
import com.jjb.www.app.AppActivity;
import com.jjb.www.http.api.CertificateDetailsApi;
import com.jjb.www.http.api.CurriculumSortApi;
import com.jjb.www.http.glide.GlideApp;
import com.jjb.www.http.httputil.HttpUtis;
import com.jjb.www.http.model.HttpData;
import com.jjb.www.http.model.HttpList;
import com.jjb.www.ui.fragment.CourseListFragment;

/**
 *    author : Android CRG
 *    github : https://github.com/getActivity/AndroidProject
 *    time   : 2019/03/01
 *    desc   : 证书详情
 */
public class CertificateDetailsActivity extends AppActivity {
    private TitleBar mTitleBar;
    private ShapeImageView mImgCert;
    private ShapeButton mBtnDown;

    private String url = "";


    @Override
    protected int getLayoutId() {
        return R.layout.activity_certificate_details;
    }

    @Override
    protected void initView() {
        mTitleBar = findViewById(R.id.titleBar);
        mImgCert = findViewById(R.id.img_cert);
        mBtnDown = findViewById(R.id.btn_down);
        setOnClickListener(mBtnDown);
    }

    @Override
    public void onClick(View view) {

        if (view==mBtnDown){
            HttpUtis.downLoad(this,this,url);
        }
    }

    @Override
    protected void initData() {
        EasyHttp.get(this)
                .api(new CertificateDetailsApi()
                .setCertificate_id(getString("cert_num")))
                .request(new HttpCallback<HttpData<CertificateDetailsApi.Bean>>(this) {

                    @Override
                    public void onSucceed(HttpData<CertificateDetailsApi.Bean> data) {
                        url = data.getData().getUrl();
                        if (data.getData().getUrl()==null){
                            mBtnDown.setVisibility(View.GONE);
                        }
                        GlideApp.with(getActivity())
                                .load(data.getData().getImg_url())
                                .into(mImgCert);
                    }

                });
    }
}